package com.john.pplay.util;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/**
 * Created by stark on 2018/7/7.
 */

public class MeasureHelp {
    private int width,height,videoWidth,videoHeight,screenWidth,screenHeight;

    private int type;
    public MeasureHelp(Context context){
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        screenWidth = dm.widthPixels;
        screenHeight = dm.heightPixels;
//        int width = dm.widthPixels;         // 屏幕宽度（像素）
//        int height = dm.heightPixels;       // 屏幕高度（像素）
//        float density = dm.density;         // 屏幕密度（0.75 / 1.0 / 1.5）
//        int densityDpi = dm.densityDpi;     // 屏幕密度dpi（120 / 160 / 240）
//        // 屏幕宽度算法:屏幕宽度（像素）/屏幕密度
//        screenWidth = (int) (width / density);  // 屏幕宽度(dp)
//        screenHeight = (int) (height / density);// 屏幕高度(dp)
    }
    public void setType(int type){
        this.type = type;
    }
    public void setSize(int w, int h){
        videoWidth = w;
        videoHeight = h;
        switch (type){
            case Setting.REAL:
                width = videoWidth;
                height = videoHeight;
                break;
            case Setting.FULL:
                width = screenWidth;
                height = screenHeight;
                break;
            case Setting.FIT:
                float videoXY = 1.0f * videoWidth /videoHeight;
                float screenXY = 1.0f * screenWidth /screenHeight;
                if (videoXY > screenXY){
                    width = screenWidth;
                    height = (int)(1.0f * width * videoHeight /videoWidth);
                }else{
                    height = screenHeight;
                    width = (int)(1.0f * height * videoWidth / videoHeight);
                }
        }
    }
    public int getWidth(){
        return width;
    }
    public int getHeight(){
        return height;
    }
}
